import store from '@/store'
import Vue from 'vue'
import VueRouter from 'vue-router'


Vue.use(VueRouter)  

const routes = [
  {
    path: '/',
    // name: 'Manager',//跳转到home路由，所以这个不需要名字了
    component: ()=>import('../views/Manager.vue'),
    //导航栏是不变的，只需要在点击不同导航栏的时候切换子路由就可以！！！
    redirect:"/home",//      “/”将会重定向到/home当中
    children: [//manager内的子路由
      {path: 'PersonInfo',name: '用户个人信息',component: ()=>import('../views/PersonInfo.vue')},
      {path: 'Teacher',name: '用户管理* / 教师管理',component: ()=>import('../views/Teacher.vue')},//meta可以定义另外的属性
      {path: 'Home',name: '首页',component: ()=>import('../views/Home.vue')},
      {path: 'Course',name: '用户管理* / 课程管理',component: ()=>import('../views/Course.vue')},
      {path: 'Teaching',name: '用户管理* / 授课管理',component: ()=>import('../views/Teaching.vue')},
      {path: 'Role',name: '用户管理* / 角色管理',component: ()=>import('../views/Role.vue')},
      {path: 'Authority',name: '用户管理* / 权限管理',component: ()=>import('../views/Authority.vue')},
      {path: 'Student',name: '班级授课信息  / 学生管理',component: ()=>import('../views/Student.vue')},
      {path: 'Grade',name: '班级授课信息  / 成绩管理',component: ()=>import('../views/Grade.vue')},
      {path: 'Customization',name: '定制  / 定制流程',component: ()=>import('../views/Customization.vue')},
      {path: 'FileUploadDownload',name: '定制  / 试卷课件管理',component: ()=>import('../views/FileUploadDownload.vue')},
      {path: 'Attendance',name: '定制  / 考勤',component: ()=>import('../views/Attendance.vue')},
    ]//子路由结束
  },
  {
    path: '/about',
    name: 'about',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  },
  {
    path:'/login',
    name:'login',
    component:()=>import('../views/login.vue')
  },
  {
    path:'/regist',
    name:'regist',
    component:()=>import('../views/regist.vue')
  },
  {
    path:'/stu-clock-in',
    name:'stu-clock-in',
    component:()=>import('../views/AttendanceStudent.vue')
  }
  // {
  //   path:'/login',
  //   name:'',
  //   component:'Login'
  // }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
//路由守卫
router.beforeEach((to,from,next) => {
  // if (to.meta.permission) {
  //   if (sessionStorage.getItem("token")) {
  //     next();
  //   } else {
  //     alert("请先登录");
  //     next("/login");
  //   }
  // } else {
  //   next();
  // }
  console.log(from);
  localStorage.setItem("currentPathName",to.name);
  store.commit("setPath")
  next()
})
export default router
